import sys
sys.path.append("../../")

from services.self_market.StockSelectService import *
from services.self_market.AccountDetailService import *
from services.CodesService import *

class SelfRunController:
    def __init__(self,args):
        self.args = args
        self.service = StockSelectService()
        self.codeService = CodeService()
        self.detailService = AccountDetailService()

    def run(self):
        if self.args["func"] == "getAll":
            return self.getAll(self.args)
        elif self.args["func"] == "getCodes":
            return self.getCodes(self.args)

    def getAll(self,args):
        actid = args["actid"]
        rs = self.service.getSelectStock(actid)
        codes = []
        for row in rs:
            codes.append(row["code"][2:])
        self.codeService.getPrice(codes, actid)

    def getCodes(self, args):
        actid = args["actid"]
        rs = self.service.getSelectStock(actid)
        codes = []
        for row in rs:
            print(row)
            codes.append(row["code"][2:])


